﻿@using System.Configuration
@{
    ViewBag.Title = "Quản Lý Biên Lai";
    Layout = "~/Views/Shared/_Admin_Layout.cshtml";
}

<div id="div-main-menu" class="left-side-bar">
    @Html.Partial("_AdminMenu")
</div>
<div id="div-main-content" class="right-side-bar">
    <h2>QUẢN LÝ BIÊN LAI</h2>
    <div class="filtering">
        <form>
            <label>Mã mượn sách bị hoãn: </label><input type="text" name="skippingID" id="skippingID" />       
            <label>Nhân viên:</label>@Html.DropDownList("employerID", (IEnumerable<SelectListItem>)ViewBag.Employees, new { id = "ID" })
            <button type="submit" id="LoadRecordsButton">Tìm kiếm</button>
        </form>
    </div>
    <div id="LibraryRecepitContainer"></div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#LibraryRecepitContainer').jtable({
            title: 'Bảng hoá đơn',
            paging: true, //Enable paging
            pageSize: @ConfigurationManager.AppSettings["PageSize"],
            sorting: true, //Enable sorting
            defaultSorting: 'SkippingID ASC',
            //openChildAsAccordion: true, //Enable this line to show child tabes as accordion style
            actions: {
                listAction: '@Url.Action("GetReceiptList", "Receipt")',
                deleteAction: '@Url.Action("DeleteReceipt","Receipt")',
                updateAction: '@Url.Action("UpdateReceipt", "Receipt")',
                createAction: '@Url.Action("AddReceipt", "Receipt")'
            },
            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                SkippingID: {
                    title: 'Mã đơn hoãn trả sách',                  
                },
                EmployerID: {
                    title: 'Nhân viên',
                    create: false,
                    edit: false,
                    options: '@Url.Action("EmployeeOptions","Employee")'
                },
                Money: {
                    title: 'Tiền đền bù'                  
                },
                Reason:{
                    title: 'Lý do',
                    type: 'textarea'
                },
                ReceiptDate: {
                    title: 'Ngày nhận',
                    type: 'date',
                    displayFormat: 'yy-mm-dd'
                },
                CheckAgreed: {
                    title: 'Kiểm tra (Đồng ý/Không đồng ý)',
                    type: 'checkbox',
                    values: { 'false': 'Không đồng ý', 'true': 'Đồng ý' },
                    defaultValue: 'false'
                },              
            },
            //validate cac field trong bang Libraty_Books
            formCreated: function (event, data) {
                data.form.find('input[name="SkippingID"]').addClass('validate[required,custom[number]]');
                data.form.find('input[name="Money"]').addClass('validate[required,custom[number]]');
                data.form.find('input[name="Reason"]').addClass('validate[required]');
                data.form.find('input[name="ReceiptDate"]').addClass('validate[required,custom[date]]');              
                data.form.validationEngine();
            },
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            formClosed: function (event, data) {
                data.form.validationEngine('hide');
                data.form.validationEngine('detach');
            },
        });
        //Load person list from server
        $('#LoadRecordsButton').click(function (e) {
            e.preventDefault();
            $('#LibraryRecepitContainer').jtable('load', {
                skippingID: $('#skippingID').val(),              
                employerID: $('#ID').val(),
            });
        });
        //Load all records when page is first shown
        $('#LoadRecordsButton').click();
    });
</script>
</div>
<div style="clear: both"></div>